package com.pengshun.modules.api.huanxin.controller;

import com.pengshun.modules.api.coal.service.dto.UserDto;
import com.pengshun.modules.api.huanxin.service.domain.HuanXinMessage;
import com.pengshun.modules.api.huanxin.service.HuanXinService;
import com.pengshun.modules.common.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/4/19
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "通讯相关")
@RequestMapping("/api/hx")
@ApiIgnore
public class HuanXinController {

    private final HuanXinService huanXinService;
    @GetMapping(value = "/token")
    public BaseResult getToken() {
        BaseResult res = huanXinService.getToken();
        return res;
    }

    /**
     * 注册用户
     * @return
     */
    @PostMapping(value = "/resgtion")
    @ApiOperation(value = "注册环信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nickName", value = "注册名称", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "用户id", dataType = "int", required = true, paramType = "query"),
    })
    public BaseResult resgtionUser(@ApiIgnore UserDto dto) {
        BaseResult res = huanXinService.resgtionUser(dto.getId(), dto.getNickName());
        return res;
    }

    @PostMapping(value = "/send-text")
    @ApiOperation(value = "发送文本消息")
    public BaseResult sendTextMessage(HuanXinMessage dto) {
        BaseResult res = huanXinService.sendTextMessage(dto.getUsers(),dto.getMsg(),dto.getFrom());
        return res;
    }


}
